//
//  MetaInfoController.m
//  iGSS
//
//  Copyright 2010 Electronic Business Systems Ltd.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#import "MetaInfoController.h"
#import "FormattingUtilities.h"
#import "GSSObject.h"

@implementation MetaInfoController

- (NSInteger)numberOfRows {
    return 4;
}

- (UITableViewCell *)cellForRow:(NSInteger)row {
    static NSString *CellIdentifier = @"MetaInfoCell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
                                       reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:13.0];
        cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
        cell.detailTextLabel.minimumFontSize = 11.0;
    }
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setDateFormat:LocalizedString(@"{Date format}")];
    
    switch (row) {
        case 0:
            cell.textLabel.text = LocalizedString(@"Path");
            cell.detailTextLabel.text = object.path;
            break;
        
        case 1:
            cell.textLabel.text = LocalizedString(@"Owner");
            cell.detailTextLabel.text = object.owner;
            break;
            
        case 2:
            cell.textLabel.text = LocalizedString(@"Created");
            if (object.creationDate && object.createdBy) {
                cell.detailTextLabel.text = [NSString stringWithFormat:
                                             @"%@ (%@)",
                                             [dateFormatter stringFromDate:object.creationDate],
                                             object.createdBy];
            } else {
                cell.detailTextLabel.text = nil;
            }
            break;
        
        case 3:
            cell.textLabel.text = LocalizedString(@"Modified");
            if (object.modificationDate && object.modifiedBy) {
                cell.detailTextLabel.text = [NSString stringWithFormat:
                                             @"%@ (%@)",
                                             [dateFormatter stringFromDate:object.modificationDate],
                                             object.modifiedBy];
            } else {
                cell.detailTextLabel.text = nil;
            }
            break;            
    }
    
    [dateFormatter release];
    
    return cell;
}

@end
